package com.yh.tea.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yh.tea.entity.RoleResource;
import com.yh.tea.model.AssignResource;
import com.yh.tea.service.RoleResourceService;
import com.yh.tea.utiity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2024-03-04
 */
@RestController
@CrossOrigin
@RequestMapping("/roleResource")
public class RoleResourceController {
    @Autowired
    private RoleResourceService roleResourceService;
    @PostMapping("/getResourceList")
    public ResponseResult getResourceList(@RequestBody RoleResource roleResource){

        return roleResourceService.getResourceList(roleResource.getRoleId());
    }
    @PostMapping("/getResource")
    public ResponseResult getResource(@RequestBody RoleResource roleResource){
        return ResponseResult.success("查询成功",roleResourceService.list(new QueryWrapper<RoleResource>().eq("status",1).eq("role_id",roleResource.getRoleId())));
    }

    /***
     * 根据提交的resourceId和roleId
     */
    @PostMapping("/assignResources")
    public ResponseResult assignResources( @RequestBody AssignResource assignResource){

        return roleResourceService.assignResources(assignResource);
    }
}

